using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
namespace MicroMsg.Scene.Voice
{
	public class DownloadVoiceStorage
	{
		private const string TAG = "DownloadVoiceDBSync";
		private const int MIN_CLEAN_INTERVAL = 600000;
		private static double mLastCleanTimeStamp = Util.getNowMilliseconds();
		public static bool updateDownloadVoiceContext(MsgTrans voiceinfo)
		{
			return StorageMgr.msgVoice.updateTransBySvrID(voiceinfo);
		}
		public static bool updateVoiceMsgStatus(string talker, int svrID, MsgUIStatus status)
		{
			ChatMsg bySvrID = StorageMgr.chatMsg.getBySvrID(talker, svrID);
			if (bySvrID != null)
			{
				bySvrID.nStatus = (int)status;
				StorageMgr.chatMsg.modifyMsg(bySvrID);
			}
			return true;
		}
		public static void loadDownloadVoiceContextList()
		{
			double nowMilliseconds = Util.getNowMilliseconds();
			if (nowMilliseconds > DownloadVoiceStorage.mLastCleanTimeStamp + 600000.0)
			{
				DownloadVoiceStorage.mLastCleanTimeStamp = nowMilliseconds;
				bool flag = StorageMgr.msgVoice.delPendingDownloadVoice();
				Log.smethod_4("DownloadVoiceDBSync", "delCompleteDownloadVoice result = " + flag);
			}
			List<MsgTrans> pendingDownLoadVoiceList = StorageMgr.msgVoice.getPendingDownLoadVoiceList();
			if (pendingDownLoadVoiceList != null && pendingDownLoadVoiceList.get_Count() != 0)
			{
				using (List<MsgTrans>.Enumerator enumerator = pendingDownLoadVoiceList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						MsgTrans current = enumerator.get_Current();
						DownloadVoiceContext downloadVoiceContext = new DownloadVoiceContext(current.nMsgSvrID, ChatMsgHelper.getTalker(current.strToUserName, current.strFromUserName));
						downloadVoiceContext.mOffset = 0;
						downloadVoiceContext.mStatus = 0;
						downloadVoiceContext.Enqueue(current);
						DownloadVoiceContextMgr.getInstance().putToTail(downloadVoiceContext);
					}
				}
				return;
			}
			Log.smethod_4("DownloadVoiceDBSync", "There is no voiceinfo in DB that need to handle");
		}
	}
}
